﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace NLBS.Web
{
   public static class RequestExtension
    {
        /// <summary>
        /// Convert query to Int
        /// </summary>
        /// <param name="strName"></param>
        /// <returns></returns>
        public static int GetQueryInt(this HttpRequest request,string strName)
        {
            int query = -1;
            if (request.QueryString[strName] != null)
            {
                try
                {
                    query = Convert.ToInt32(request.QueryString[strName]);
                }
                catch (Exception e)
                {
                    throw new Exception("参数不正确");
                    throw e;
                }
            }
            return query;
        }

        /// <summary>
        /// Convert query to Guid
        /// </summary>
        /// <param name="strName"></param>
        /// <returns></returns>
        public static Guid? GetQueryGuid(this HttpRequest request, string strName)
        {
            Guid query = new Guid();
            if (request.QueryString[strName] != null)
            {
                try
                {
                    query = new Guid(request.QueryString[strName]);
                    return query;
                }
                catch (Exception e)
                {
                    return null;
                    throw new Exception("参数不正确");
                    throw e;
                }
            }
            return null;
        }
    }
}
